import ash from '@ash.ts/ash';
import { BulletAgeNode } from '../data/nodes';
import { EntityCreator } from '../util/EntityCreator';

export class BulletAgeSystem extends ash.ListIteratingSystem<BulletAgeNode> {
    private creator: EntityCreator;

    public constructor(creator: EntityCreator) {
        super(BulletAgeNode);
        this.creator = creator;
    }

    public updateNode(node: BulletAgeNode, time: number): void {
        const { bullet } = node;
        bullet.lifeTime -= time;
        if (bullet.lifeTime <= 0) {
            this.creator.destroyEntity(node.entity);
        }
    }
}
